﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using MacViet.DataBaseAPI;
using System.Web.Mail;

public partial class Control_Admin_UCAccount_Login : System.Web.UI.UserControl
{    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            
            if (Request.QueryString["SecurityCode"] != null)
            {
                lblSecurityCode.Visible = true;
                txtSecurityCode.Visible = true;

            }
            else
            {
                lblSecurityCode.Visible = false;
                txtSecurityCode.Visible = false;
            }           
            

        }
    }

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        ACCOUNTSDataAPI api = new ACCOUNTSDataAPI();
        string email = txtEmail.Text.Trim();
        string password = txtPassword.Text.Trim();
        string securityCode = txtSecurityCode.Text.Trim();
        bool checkLogin = api.AccountCheckLogin(email,password,securityCode);
        if (checkLogin)
        {
            Session["ACC_EMAIL"] = email;
            DataTable dt = api.getAccountByEmail(email);
            if(dt!=null)
                Session["ACC_ID"]=dt.Rows[0]["ACC_ID"].ToString();
            Response.Redirect("Default.aspx");
        }
        else
        {
            Response.Write("<script>alert('The email or password is invalid!')</script>");
            
        }
    }

    
}
